package serverAndThreads;

import java.io.*;
import java.net.*;
import java.util.*;

public class ChatServer extends Thread {
	boolean started = false;
	ServerSocket serverSocket = null;
	ServerSocket chatSocket = null;
	ArrayList clients = new ArrayList();

	public ChatServer() {
		this.start();
	}

	public void run() {
		try {
			serverSocket = new ServerSocket(6999);
			chatSocket = new ServerSocket(7500);
			started = true;
		} catch (Exception e) {
			e.printStackTrace();
		}

		DataInputStream client_id_input;
		DataOutputStream client_id_output;

		try {
			while (true) {

				Socket socket = serverSocket.accept();

				client_id_input = new DataInputStream(socket.getInputStream());
				client_id_output = new DataOutputStream(
						socket.getOutputStream());
				int chat_id = client_id_input.readInt();
				client_id_output.writeUTF("ok");
				System.out.println("OK");

				new chatThread(chat_id).start();

			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				serverSocket.close();
			} catch (IOException e2) {
				e2.printStackTrace();
			}
		}

	}
}
